<template>
  <div class="ycdwrap" id="ycdwrap">
    <div class="yc-table-wrp">
      <div>
        <yc-title class="title" value="版本管理"></yc-title>
      </div>
      <div class="acc-man-body">
        <label class="yc-table">版本名称</label>
        <el-input maxlength="30" v-model="search" style="width: 200px;height: 36px;margin: 0 22px" class="input"></el-input>
        <yc-search-button @click="handleSearch"></yc-search-button>
      </div>
      <yc-button class="newadd" @click="handleShowAdd" value="新增"></yc-button>
      <yc-table  ref="getPage" :total="total" :tableData="tableInfo"></yc-table>
    </div>
    <!--  弹框 添加角色-->
    <div class="newadddcmd">
      <el-dialog class="newDialong" id="addRole" title="添加角色"  top="250px" :visible.sync="show">
        <el-form label-position="left" :model="form">
          <el-form-item label="角色名称" label-width="80px">
            <el-input maxlength="30" style="width: 86%;" v-model="form.roleName" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="角色状态" label-width="80px">
            <el-select style="width: 86%;" v-model="form.available" placeholder="请选择角色状态">
              <el-option label="正常" value="1"></el-option>
              <el-option label="禁用" value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancleBtn" @click="show = false">取 消</el-button>
          <el-button type="primary" @click="handSure">保 存</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import request from 'request'
import ycTable from './com/table'
import ycButton from '@/components/button.vue'
import ycTitle from '@/components/ycTitle.vue'
import ycSearchButton from '@/components/searchButton.vue'
export default {
  name: 'roleManage',
  components: {
    ycTable,
    ycTitle,
    ycButton,
    ycSearchButton
  },
  data () {
    return {
      tableInfo: [],
      search: '',
      show: false,
      editShow: false,
      total: null,
      form: {
        roleName: '',
        available: ''
      }
    }
  },
  methods: {
    cleraAdd () {
      this.form.available = ''
      this.form.roleName = ''
    },
    handSure () {
      if (!this.form.available) {
        this.$message.error('请输角色名称')
        return
      } else if (!this.form.roleName) {
        this.$message.error('请输角色状态')
        return
      }
      request.addRole({
        available: this.form.available,
        roleName: this.form.roleName
      }).then(res => {
        if (res) {
          this.$message({
            message: '添加成功',
            type: 'success'
          })
          setTimeout(() => {
            this.init(this.$refs.getPage.currentPage)
          }, 500)
        }
      }).catch(res => {
        this.$message.error('添加失败')
      })
      this.show = false
    },
    handleShowAdd () {
      this.cleraAdd()
      this.show = true
    },
    init (val) {
      request.getRoleManage({
        params: {
          p: val || 1,
          roleName: this.search || '',
          size: 10
        }
      }).then(res => {
        this.total = res.total
        this.tableInfo = res.records
      })
    },
    handleSearch () {
      this.init()
    }
  }
}
</script>

<style lang="stylus" scoped="scoped">
.yc-table-wrp{
  .acc-man-body{
    padding 20px 0 0 0
  }
  .newadd{
    float right
    margin 20px 0
  }
}
</style>
